package common 
{
	import debug.ASSERT;
	/**
	 * 分组数据
	 * @author anod
	 */
	public class StructGroup implements IData
	{
		private var mID:int;
		private var mName:String;
		private var mMembers:Array;
		
		public function StructGroup( id:int ) 
		{
			mID = id;
			mMembers = new Array();
		}
		
		public function get ID():int 
		{
			return mID;
		}
		
		public function get name():String 
		{
			return mName;
		}
		
		public function set name(value:String):void 
		{
			ASSERT( value != null, "分组名称不能为空" );
			mName = value;
		}
		
		public function get members():Array 
		{
			return mMembers.concat();
		}
		
		public function copyMembersFrom( members:Array ):void
		{
			mMembers.length = 0;
			for each( var member:Object in members )
			{
				var number_test:Number = Number( member );
				( isNaN(number_test) ) && mMembers.push( member.ID ) || mMembers.push( number_test );
			}
		}
		
		public function addMember( member:int ):int
		{
			(mMembers.indexOf( member ) < 0) && mMembers.push( member );
			return mMembers.length;
		}
		public function delMember( member:int ):int
		{
			var pos:int = mMembers.indexOf( member );
			(pos >= 0) && mMembers.splice( pos, 1 );
			return mMembers.length;
		}
		
		/* INTERFACE common.IData */
		
		public function loadFromXML(xml:XML):void 
		{
			ASSERT( xml != null, "加载的xml为空" );
			//<item name="xxoo">1,2,3</item>
			mName = String( xml.@name );
			copyMembersFrom( xml.toString().split(",") );
		}
		
		public function toXML():String 
		{
			return '<item name="' + mName + '">' + mMembers.join(",") + '</item>';
		}
	}

}